﻿Imports System.Runtime.CompilerServices
Imports System.Text.RegularExpressions
Imports System.Web
Imports System.Net

Public Module ExtensionModule

    <Extension()> _
    Public Function DecodeValue(ByVal group As Capture) As String

        Dim text = group.Value.Replace(vbCrLf, "").Replace("<br />", vbCrLf)
        text = HttpUtility.HtmlDecode(Regex.Replace(text, "<.*?>", "", RegexOptions.Singleline))
        Return Regex.Replace(text, "(\r\n)+", vbCrLf).Trim

    End Function

    <Extension()> _
    Public Function DecodeValue(ByVal text As String) As String

        text = text.Replace(vbCrLf, "").Replace("<br />", vbCrLf)
        text = HttpUtility.HtmlDecode(Regex.Replace(text, "<.*?>", "", RegexOptions.Singleline))
        Return Regex.Replace(text, "(\r\n)+", vbCrLf).Trim

    End Function

    <Extension()> _
    Public Function MatchedText(ByVal inputText As String, ByVal pattern As String, ByVal label As String) As String
        Dim match = Regex.Match(inputText.Replace(vbLf, "").Replace(vbCr, "").Trim, pattern, RegexOptions.Singleline)
        If match.Success Then
            Return match.Groups(label).Value
        Else
            Return ""
        End If
    End Function

    <Extension()> _
    Public Function MatchedText(ByVal inputText As String, ByVal pattern As String) As String
        Dim match = Regex.Match(inputText.Replace(vbLf, "").Replace(vbCr, "").Trim, pattern, RegexOptions.Singleline)
        If match.Success Then
            Return match.Value
        Else
            Return ""
        End If
    End Function

End Module
